package com.xingda.packing.minitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xingda.packing.minitor.entity.PkVisualSense;
import com.xingda.packing.minitor.mapper.PkVisualSenseMapper;
import com.xingda.packing.minitor.service.PkVisualSenseService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Objects;

@Service
public class PkVisualSenseServiceImpl extends ServiceImpl<PkVisualSenseMapper, PkVisualSense> implements PkVisualSenseService {
    @Resource
    private PkVisualSenseMapper pkVisualSenseMapper;

    @Override
    public IPage<PkVisualSense> getList(Integer area, Long current, Long size, String keyword) {
        LambdaQueryWrapper<PkVisualSense> pkVisualSenseLambdaQueryWrapper = Wrappers.lambdaQuery();
        if (Objects.isNull(area)) {
            pkVisualSenseLambdaQueryWrapper.in(PkVisualSense::getArea, 1, 2, 3);
        } else {
            pkVisualSenseLambdaQueryWrapper.eq(PkVisualSense::getArea, area);
        }
        pkVisualSenseLambdaQueryWrapper.like(StringUtils.hasText(keyword), PkVisualSense::getScanWheelNo, keyword).orderByDesc(PkVisualSense::getCreateTime);
        current = current == null ? 1 : current;
        size = size == null ? 20 : size;
        IPage<PkVisualSense> page = new Page<>(current, size);
        return pkVisualSenseMapper.selectPage(page, pkVisualSenseLambdaQueryWrapper);
    }
}
